﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WXYW.BLL;
using WXYW.DAL;

namespace WXYW
{
    public partial class ZCDetail : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                backLinkButton.PostBackUrl = string.Format("ZCAllList.aspx?Type={0}", Request.QueryString["Type"]);
                BindApplication();
            }
        }

        private void BindApplication()
        {
            long applicationID = Convert.ToInt64(Request.QueryString[Constants.QUERYSTR_APPLICATION_ID]);
            ZCService service = new ZCService();
            ZCApplicationForm form = service.GetApplication(applicationID);
            applicationCodeLbl.Text = form.ApplicationCode;
            applicationDateLbl.Text = form.ApplicationDate.ToString("yyyy-MM-dd");
            fromFactoryLbl.Text = form.FromFactory;
            toFactoryLbl.Text = form.ToFactory;
            fromKCLbl.Text = form.FromKC;
            toKCLbl.Text = form.ToKC;
            commentLbl.Text = form.Comment;
            if (form.User != null)
            {
                applicantLbl.Text = form.User.ContactPerson;
            }
            if (form.User1 != null)
            {
                user1Lbl1.Text = form.User1.ContactPerson;
                user1Lbl.Text = form.User1.ContactPerson;

                user1SignDateLbl.Text = form.User1SignDate.HasValue ? form.User1SignDate.Value.ToString("yyyy-MM-dd") : "";
                user1SignCommentLbl.Text = form.User1SignType + ": " + form.User1SignComment;
            }
            if (form.User2 != null)
            {
                user2Lbl1.Text = form.User2.ContactPerson;
                user2Lbl.Text = form.User2.ContactPerson;

                user2SignDateLbl.Text = form.User2SignDate.HasValue ? form.User2SignDate.Value.ToString("yyyy-MM-dd") : "";
                user2SignCommentLbl.Text = form.User2SignType + ": " + form.User2SignComment;
            }
            if (form.User3 != null)
            {
                user3Lbl1.Text = form.User3.ContactPerson;
                user3Lbl.Text = form.User3.ContactPerson;

                user3SignDateLbl.Text = form.User3SignDate.HasValue ? form.User3SignDate.Value.ToString("yyyy-MM-dd") : "";
                user3SignCommentLbl.Text = form.User3SignType + ": " + form.User3SignComment;
            }
            materialGridView.DataSource = service.GetMaterials(applicationID);
            materialGridView.DataBind();
        }
    }
}
